﻿@model Bricks.Site.Models.ContractFilterView

@{
    ViewBag.Title = "涵洞统计";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}

<script type="text/javascript">
    $(function () {
        CulvertStatistics.InitProject();
    });

    var CulvertStatistics = {
        //初始化项目下拉框
        InitProject: function () {
            $("#ProjectID").combobox({
                editable: false, panelHeight: "auto",
                valueField: 'ID',
                textField: 'ProjectName',
                url: '/ProjectInfo/ProjectInfoListForFlow',
                onLoadSuccess: function () {
                    var data = $("#ProjectID").combobox('getData');
                    if (data.length > 0) {
                        $("#ProjectID").combobox('select', data[0]["ID"]);
                    }
                },
                onSelect: function (record) {
                    $("#hProjectID").val(record.ID);
                    CulvertStatistics.InitContract(record.ID);

                    CulvertStatistics.InitCulvertDetailGrid("");
                }
            });
        },

        //初始化标段下拉框
        InitContract: function (projectID) {
            $("#ContractID").combobox({
                editable: false, panelHeight: "auto",
                valueField: 'ID',
                textField: 'ContractName',
                url: '/ContractInfo/ContractInfoListByProjectID?projectID=' + projectID,
                onLoadSuccess: function () {
                    var data = $("#ContractID").combobox('getData');
                    if (data.length > 0) {
                        $("#ContractID").combobox('select', data[0]["ID"]);
                    }
                },
                onSelect: function (record) {
                    $("#hContractID").val(record.ID);
                    CulvertStatistics.InitCulvertGrid(projectID, record.ID);

                    CulvertStatistics.InitCulvertDetailGrid("");
                }
            });
        },

        //初始化涵洞列表
        InitCulvertGrid: function (projectID, contractID) {
            $('#culvertGrid').datagrid({
                url: '/CulvertStatistics/GetCulvertTotalList?projectID=' + projectID + '&contractID=' + contractID,
                nowrap: true,
                autoRowHeight: false,
                striped: true,
                collapsible: true,
                rownumbers: true,
                remoteSort: false,
                idField: 'ID',
                checkOnSelect: true,
                selectOnCheck: true,
                singleSelect: true,
                columns: [[
                    { title: 'ID', field: 'ID', hidden: true },
                    { title: '统计周期', field: 'StatisticalCycle', width: 120, rowspan: 2, align: 'center' },
                    { title: '长度（延米）', field: '', width: 120, colspan: 2 },
                    { title: '实际完成进度%', field: '', width: 230, colspan: 5 },
                    { title: '总完成进度(%)', field: 'TotalFinishedProgress', width: 100, rowspan: 2, align: 'center' }
                ],
                    [
                         { title: '设计', field: 'LengthDesignTotal', align: 'center', width: 90 },
                         { title: '实际', field: 'LengthRealityTotal', align: 'center', width: 90 },
                         { title: '基础', field: 'BasicProgressTotal', align: 'center', width: 90 },
                         { title: '墙身', field: 'WallBodyProgressTotal', align: 'center', width: 90 },
                         { title: '盖板', field: 'BlindFlangeProgressTotal', align: 'center', width: 90 },
                         { title: '台背回填', field: 'BackfillProgressTotal', align: 'center', width: 90 },
                         { title: '洞口建筑', field: 'BuildingProgressTotal', align: 'center', width: 90 }
                    ]],
                toolbar: '#culvertToolBar',
                onClickRow: function (rowIndex, rowData) {
                    CulvertStatistics.InitCulvertDetailGrid(rowData.ID);
                },
                onLoadSuccess: function (data) {
                    if (data.rows.length > 0) {
                        $('#culvertGrid').datagrid('selectRow', 0);
                        var row = $("#culvertGrid").datagrid("getSelected");
                        if (row) {
                            CulvertStatistics.InitCulvertDetailGrid(row.ID);
                        }

                    }
                }
            });
        },

        //初始化涵洞明细列表
        InitCulvertDetailGrid: function (culvertID) {
            $('#culvertDetailGrid').datagrid({
                url: '/CulvertStatistics/GetCulvertDetailList?culvertID=' + culvertID,
                nowrap: true,
                autoRowHeight: false,
                striped: true,
                collapsible: true,
                rownumbers: true,
                remoteSort: false,
                idField: 'ID',
                checkOnSelect: true,
                selectOnCheck: true,
                singleSelect: true,
                columns: [[
                    { title: 'ID', field: 'ID', hidden: true },
                    { title: '通涵类型', field: 'CulvertType', width: 120, rowspan: 3, align: 'center' },
                    { title: '中心桩号', field: 'CenterPileNumber', width: 100, rowspan: 3, align: 'center' },
                    { title: '通涵', field: '', width: 900, colspan: 8, align: 'center' }
                ],
                    [
                         { title: '长度（延米）', field: '', colspan: 2, align: 'center', width: 160 },
                         { title: '实际完成进度%', field: '', colspan: 5, align: 'center', width: 160 },
                         { title: '总完成进度(%)', field: 'TotalFinishedProgress', rowspan: 2, align: 'center', width: 100 }
                    ],
                    [
                         { title: '设计', field: 'LengthDesign', align: 'center', width: 80 },
                         { title: '实际', field: 'LengthReality', align: 'center', width: 80 },
                         { title: '基础', field: 'BasicProgress', align: 'center', width: 80 },
                         { title: '墙身', field: 'WallBodyProgress', align: 'center', width: 80 },
                         { title: '盖板', field: 'BlindFlangeProgress', align: 'center', width: 80 },
                         { title: '台背回填', field: 'BackfillProgress', align: 'center', width: 80 },
                         { title: '洞口建筑', field: 'BuildingProgress', align: 'center', width: 80 }
                    ]]
                //toolbar: '#culvertDetailToolBar'
            });
        },

        //新增
        Add: function () {
            if ($("#hProjectID").val() == '' || $("#hContractID").val() == '') {
                $.messager.alert('操作提示', "项目和标段不能为空！", 'info');
            }
            else {
                $.post("/UserMenuAction/GetUserDepartmentForFlow?menuCode=CulvertStatistics", function (userDepartment) {
                    if (userDepartment == "") {
                        showMyWindow("#myWindow", "选择机构", "/UserMenuAction/ShowOrgByUserForFlow?menuCode=CulvertStatistics", 500, 280, true, false);
                    }
                    else if (userDepartment == "**********") {
                        $.messager.alert('操作提示', '当前用户不属于任何机构，请先设置所属机构！', 'info');
                    }
                    else if (userDepartment == "++++++++++") {
                        $.messager.alert('操作提示', '当前用户的机构不属于流程申请配置机构，不能新增！', 'info');
                    }
                    else {

                        //showMyWindow("#myWindow", "", '/YearPlan/YearPlan?MenuCode=YearPlan&sourceType=1&processType=&sourceID=&lastUpdateUserDepartment=' + userDepartment + '&projectID=' + $("#hProjectID").val() + '&contractType=' + encodeURI($("#ContractType").val()) + '&contractID=' + $("#hContractID").val(), 1000, 500, true, true, true);
                        showMyWindow("#myWindow", "", '/CulvertStatistics/Edit?MenuCode=CulvertStatisticsDetail&sourceType=1&processType=&sourceID=&lastUpdateUserDepartment=' + userDepartment + '&projectID=' + $("#hProjectID").val() + '&contractID=' + $("#hContractID").val(), 1000, 500, true, true, true);
                    }
                });
            }
        },

        //修改
        Edit: function () {

            var row = $("#culvertGrid").datagrid("getSelected");
            if (row) {
                $.post("/UserMenuAction/GetUserDepartmentForFlow?menuCode=CulvertStatistics", function (userDepartment) {
                    showMyWindow("#myWindow", "", '/CulvertStatistics/Edit?MenuCode=CulvertStatisticsDetail&sourceType=2&processType=&sourceID=&lastUpdateUserDepartment=' + userDepartment + '&projectID=' + $("#hProjectID").val() + '&contractID=' + $("#hContractID").val() + '&culvertID=' + row.ID, 1000, 500, true, true, true);
                });
            }
            else { $.EasyuiSlide("请选择一条记录"); }
        },

        //删除
        Delete: function () {
            var row = $("#culvertGrid").datagrid("getSelected");
            if (row) {
                $.messager.confirm('操作提示', "确认删除[ " + row.StatisticalCycle + " ]吗？", function (r) {
                    if (r) {
                        $.post("/CulvertStatistics/Delete?culvertID=" + row.ID, function (result) {
                            debugger;
                            if (result.ResultType == 0) {  //0表示成功
                                //移除删除的数据
                                $.EasyuiSlide(result.Message);
                                CulvertStatistics.Reload();
                            }
                            else {
                                $.EasyuiMsg(result.Message);
                            }
                        });
                    }
                });
            }
            else {
                $.EasyuiSlide("请选择一条记录");
            }
        },

        //重新加载数据
        Reload: function () {
            $("#culvertGrid").datagrid("reload");
        }
    }

    function cancelPopWindow(handleState) {
        if (handleState == "0") {
            $("#culvertGrid").datagrid("reload");
        }
        colseMyWindow("#myWindow");
    }

    function CloseWindow(data) {
        colseMyWindow("#myWindow");
        $("#culvertGrid").datagrid("reload");
        $.EasyuiSlide(data);
    }
</script>

<div class="easyui-layout" style="height:580px;">
    <input type="hidden" id="hProjectID" name="ProjectID" value="@Model.ProjectID" />
    <input type="hidden" id="hContractID" name="ContractID" value="@Model.ContractID" />
    <div data-options="region:'north'" style="height:35px;">
        <table style="margin-top: 5px">
            <tr id="trCommon">
                <td style="width: 95px; text-align: center">项目名称</td>
                <td>
                    <input id="ProjectID" name="ProjectID" class="easyui-combobox" style="width: 200px;" />
                </td>
                <td style="width: 95px; text-align: center">标段名称</td>
                <td colspan="3">
                    <input id="ContractID" name="ContractID" class="easyui-combobox" style="width: 200px;" />
                </td>
            </tr>
        </table>
    </div>
    <div data-options="region:'center'">
        <div class="easyui-layout" fit="true">
            <div data-options="region:'north'" style="height:250px;">
                <table id="culvertGrid" fit="true"></table>
                <div id="culvertToolBar">
                    @*<a href='javascript:void(0)' class='easyui-linkbutton' onclick='CulvertStatistics.Add()' data-options='plain:true,iconCls:"icon-application_add"'>新增</a>
                    <a href='javascript:void(0)' class='easyui-linkbutton' onclick='CulvertStatistics.Edit()' data-options='plain:true,iconCls:"icon-application_delete"'>修改</a>
                    <a href='javascript:void(0)' class='easyui-linkbutton' onclick='CulvertStatistics.Delete()' data-options='plain:true,iconCls:"icon-bell"'>删除</a>
                    <a href='javascript:void(0)' class='easyui-linkbutton' onclick='CulvertStatistics.Reload()' data-options='plain:true,iconCls:"icon-bank"'>刷新</a>*@
                    @Html.Raw(ViewBag.ToolBarInfo)
                </div>
            </div>
            <div data-options="region:'center'">
                <table id="culvertDetailGrid" fit="true" style="width:1880px;"></table>
            </div>
        </div>
    </div>
</div>
